const MyPromise = require("./MyPromise")

new MyPromise((resolve, reject) => {
    setTimeout(() => {
        Math.random() > 0 ? resolve("data") : reject(new Error("一张好人卡"));
    }, 2000);
})
.then(
    data => {
        console.log("then1:data=",data)
        return "data from then1"
        // throw new Error("err from then1")
    }
)
.then(
    data => {
        console.log("then2:data=",data)
        return MyPromise.resolve("data from then2")
    }
)
.then(
    data => {
        console.log("then3:data=",data)
        return new MyPromise(
            (resolve,reject) => setTimeout(() => {
                reject("err from then3")
            }, 2000)
        )
    }
)
.then(
    data => console.log("then4:data=",data)
)
.catch(
    err => console.log("catch1:err=",err)
)
.catch(
    err => console.log("catch2:err=",err)
)
.finally(
    ()=>console.log("finally:game over!")
)